import type { AppRouteRecordRaw, AppRouteModule } from '/@/router/types';

import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';

import { mainOutRoutes } from './mainOut';
import { PageEnum } from '/@/enums/pageEnum';
import { t } from '/@/hooks/web/useI18n';

const modules = import.meta.glob('./modules/**/*.ts', { eager: true });

const routeModuleList: AppRouteModule[] = [];

Object.keys(modules).forEach((key) => {
  const mod = (modules as Recordable)[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  routeModuleList.push(...modList);
});

export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];

export const RootRoute: AppRouteRecordRaw = {
  path: '/',
  name: 'Root',
  redirect: PageEnum.BASE_LOGIN,
  meta: {
    title: 'Root',
  },
};

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('/@/views/sys/login/Login.vue'),
  meta: {
    title: t('routes.basic.login'),
  },
};

const ModPwdRoute: AppRouteModule = {
  path: '/modPwd',
  name: 'ModPwd',
  component: () => import('/@/views/sys/account/modPwd.vue'),
  meta: {
    icon: 'i-ion:key-outline',
    title: t('sys.account.modifyPwd'),
  },
};
const ProductRoute: AppRouteRecordRaw[] = [
  {
    path: '/client',
    name: 'Product',
    component: () => import('/src/views/jydq/product/client/index.vue'),
    redirect: '/client/home',
    meta: {
      title: t('商品展示'),
    },
    children: [
      {
        path: 'index',
        name: 'Shop',
        component: () => import('/src/views/jydq/product/client/Home.vue'),
        meta: {
          title: t('商品首页'),
        },
      },
      {
        path: 'productDetail',
        name: 'ProductDetail',
        component: () => import('/src/views/jydq/product/client/productDetail.vue'),
        meta: {
          title: t('商品列表'),
        },
      },
      {
        path: 'Favorite',
        name: 'Favorite',
        component: () => import('/src/views/jydq/product/client/Favorite.vue'),
        meta: {
          title: t('我的收藏'),
        },
      },
      {
        path: 'ProductDetail1',
        name: 'ProductDetail1',
        component: () => import('/src/views/jydq/product/client/ProductDetail1.vue'),
        meta: {
          title: t('商品详情'),
        },
      },
      {
        path: 'Comment',
        name: 'Comment',
        component: () => import('/src/views/jydq/product/client/Comment.vue'),
        meta: {
          title: t('用户评价'),
        },
      },
      {
        path: 'center',
        name: 'center',
        component: () => import('/src/views/jydq/product/client/center.vue'),
        meta: {
          title: t('用户信息'),
        },
      },
      {
        path: 'modPwd',
        name: 'modPwd',
        component: () => import('/src/views/sys/account/modPwd.vue'),
        meta: {
          title: t('用户信息'),
        },
      },
    ],
  },
  // {
  //   path: '/prtp/login',
  //   name: 'BiddingPortalLogin',
  //   component: () => import('/src/views/bidding/portal/login.vue'),
  //   meta: {
  //     title: t('投标人登录-中国电建集团港航建设有限公司-公共资源交易平台'),
  //   },
  // },
];

// Basic routing without permission
export const basicRoutes = [
  LoginRoute,
  ModPwdRoute,
  RootRoute,
  ...ProductRoute,
  ...mainOutRoutes,
  REDIRECT_ROUTE,
  PAGE_NOT_FOUND_ROUTE,
];
